<!-- 物资采购添加 -->
<template>
  <div>
    <h2>基本信息</h2>
    <el-form ref="form"  :model="form" label-width="80px">
      <el-form-item label="货物名称" required>
        <el-input v-model="form.cargoName" placeholder="请输入货物名称"></el-input>
      </el-form-item>
      <el-form-item label="类型" required>
        <el-select
          v-model="form.typeID"
          placeholder="请选择货物分类"
          style="float: left"
        >
          <el-option label="车辆用品" value="441DD4A3-58F4-F35C-C517-EC783846756B"></el-option>
          <el-option label="办公用品" value="307916DC-5C15-DCE0-568E-29BBD8858D6C"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="材质" required>
        <el-select
          v-model="form.textureID"
          placeholder="请选择材质分类"
          style="float: left"
        >
          <el-option label="金属" value="C4B257EC-15AC-64AF-8581-8A86A6355041"></el-option>
          <el-option label="橡胶" value="EF19EE03-63AC-923E-4EC0-F53864FAF4DA"></el-option>
          <el-option label="塑料" value="B8A7DAB5-FBCB-380C-EA08-84A67B6BA2FA"></el-option>
          <el-option label="液体" value="F18A8F75-885B-6020-41F1-83869AD88184"></el-option>
          <el-option label="纸质" value="FAE70E35-24D4-7995-6670-F8BE2774E517"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="规格" required>
        <el-input v-model="form.skuName" placeholder="请输入规格"></el-input>
      </el-form-item>
      <el-form-item label="产地" required>
        <el-select
          v-model="form.addrID"
          placeholder="请选择地址"
          style="float: left"
        >
          <el-option label="中国" value="11639B30-862A-C011-F89C-B4DEB460A3F8"></el-option>
          <el-option label="美国" value="49B3FF3C-8B9E-B36D-E521-731623D99D84"></el-option>
          <el-option label="俄罗斯" value="16A2BC18-D2FD-A141-29D4-96ECEA43EEBD"></el-option>
          <el-option label="法国" value="E0133E44-FE4B-064B-DD13-40345488B650"></el-option>
          <el-option label="德国" value="3579431F-3C46-29EE-838E-47C4BF60324A"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="数量" required>
        <el-input-number v-model="form.number" placeholder="数量" :step='1'></el-input-number>
      </el-form-item>
      <el-form-item label="期望交付日期" required>
        <el-date-picker v-model="form.expectTime" format="yyyy-MM-dd" value-format="yyyy-MM-dd"
          :style="{width: '100%'}" placeholder="请选择日期" clearable></el-date-picker>
      </el-form-item>
      <el-form-item label="用途描述" required>
        <el-input v-model="form.useInfo"></el-input>
      </el-form-item>
      <el-form-item label="备注" required>
        <el-input v-model="form.remark"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit(form)">提交</el-button>
        <el-button type="Danger" @click="QXCollectionFrom">取消</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>


<script>
import axios from "axios";
export default {
  data() {
    return {
      form: {
        cargoName :"",
        typeID   :"", 
        textureID :"",
        skuName   :"",
        addrID    :"",
        number    :"",
        useInfo   :"",
        expectTime:"",
        remark    :"",
      },
      rules: {
        cargoID: [{
          required: true,
          message: '请输入ID',
          trigger: 'blur'
        }],
        cargoName: [{
          required: true,
          message: '请输入货物名称',
          trigger: 'blur'
        }],
        typeID: [{
          required: true,
          message: '请选择货物分类',
          trigger: 'change'
        }],
        textureID: [{
          required: true,
          message: '请选择材质分类',
          trigger: 'change'
        }],
        skuName: [{
          required: true,
          message: '请输入规格',
          trigger: 'blur'
        }],
        space: [{
          required: true,
          message: '请选择地区',
          trigger: 'change'
        }],
        number: [{
          required: true,
          message: '数量',
          trigger: 'blur'
        }],
        useInfo: [{
          required: false,
          message: '请输入用途',
          trigger: 'blur'
        }],
        expectTime: [{
          required: true,
          message: '请输入预期完成',
          trigger: 'blur'
        }],
        remark: [{
          required: false,
          message: '请输入备注',
          trigger: 'blur'
        }],
      },
    };
  },
  methods: {
    onSubmit(form) {
      this.axios({
        url: "https://localhost:44331/api/app/cargo_Information/cargo",
        method: "post",
        data: form,
      }).then((res) => {
        if (res.status == 200) {
          this.$message.success("添加成功");
          this.$router.push("/Show/Cargo_Information");
        } else {
          this.$message.error("添加失败");
          this.reload(); //局部刷新
        }
      });
    },
    QXCollectionFrom() {
      this.$router.push("/Show/Cargo_Information");
    },
  },
};
</script>
